package com.yogee.topseller.view;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.yogee.topseller.R;

/**
 * @auathor ${XiaoJianghong}
 * @date 2017/7/3.
 */
public class VoucherPop {
    private View bgView;
    private Context context;
    public PopupWindow popupWindow;
    private OnIdCardPopClickListener listener;

    public VoucherPop(View bgView, Context context, OnIdCardPopClickListener listener) {
        this.bgView = bgView;
        this.context = context;
        this.listener = listener;
    }

    /**
     * 拍照弹出的popupwindow
     *
     */
    public void idCardPop() {
        bgView.setVisibility(View.VISIBLE);
        bgView.getBackground().setAlpha(76);
        View contentView = LayoutInflater.from(context).inflate(
                R.layout.pop_voucher, null);

        popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        TextView xiangce = (TextView) contentView.findViewById(R.id.pop_album_tv);
        TextView camera = (TextView) contentView.findViewById(R.id.pop_camera_tv);
        TextView quxiao = (TextView) contentView.findViewById(R.id.pop_cancel_tv);
        View v = contentView.findViewById(R.id.bg_chick_v);

        xiangce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onAlbumClick();
                popupWindow.dismiss();
            }
        });
        camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onCameraClick();
                popupWindow.dismiss();
            }
        });
        quxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                bgView.setVisibility(View.GONE);
            }
        });
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setTouchable(true);
        popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        popupWindow.showAtLocation(contentView, Gravity.BOTTOM, 0, 0);
    }

    public interface OnIdCardPopClickListener {
        void onCameraClick();

        void onAlbumClick();
    }
}